<?php
/**
 * Created by PhpStorm.
 * User: 12133
 * Date: 2024/1/13
 * Time: 9:27
 */

namespace app\controller\admin;

use think\facade\Cookie;
use think\facade\View;
use app\model\admin\Admin AS model;
class Login
{
    /**
     * 渲染登录页面
     * @return string
     */
    public function sign(){
        return View::fetch('/admin/login');
    }

    public function login(){
        $username = input('username');
        $password = Input('password');
        $find = model::where('username',$username)->find();
        if (empty($find->password)) {
            View::assign('error','账号不存在');
            return View::fetch('/error');
        }else{
            if($find->password != $password) {
                View::assign('error', '密码不正确');
                return View::fetch('/error');
            }
            Cookie::set('user',$find);
            return redirect('/admin/index/index');
        }
    }

    public function unlogin(){
        Cookie::delete('user');
        return View::fetch('/error/401');
    }
}